package com.yuexunit.operationman.nbsy.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.module.SurgicalReceipt.Bean.CompareBean;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/10/26 0026.
 */

public class CompareDialog {

    @Bind(R.id.compare_name_tv_01)
    TextView compareNameTv01;
    @Bind(R.id.compare_name_tv_02)
    TextView compareNameTv02;
    @Bind(R.id.compare_type_01_01)
    TextView compareType0101;
    @Bind(R.id.compare_type_01_02)
    TextView compareType0102;
    @Bind(R.id.compare_type_ll_01)
    LinearLayout compareTypeLl01;
    @Bind(R.id.compare_type_02_01)
    TextView compareType0201;
    @Bind(R.id.compare_type_02_02)
    TextView compareType0202;
    @Bind(R.id.compare_type_ll_02)
    LinearLayout compareTypeLl02;
    @Bind(R.id.compare_type_03_01)
    TextView compareType0301;
    @Bind(R.id.compare_type_03_02)
    TextView compareType0302;
    @Bind(R.id.compare_type_ll_03)
    LinearLayout compareTypeLl03;
    @Bind(R.id.compare_type_04_01)
    TextView compareType0401;
    @Bind(R.id.compare_type_04_02)
    TextView compareType0402;
    @Bind(R.id.compare_type_ll_04)
    LinearLayout compareTypeLl04;
    @Bind(R.id.compare_type_05_01)
    TextView compareType0501;
    @Bind(R.id.compare_type_05_02)
    TextView compareType0502;
    @Bind(R.id.compare_type_ll_05)
    LinearLayout compareTypeLl05;
    @Bind(R.id.compare_type_06_01)
    TextView compareType0601;
    @Bind(R.id.compare_type_06_02)
    TextView compareType0602;
    @Bind(R.id.compare_type_ll_06)
    LinearLayout compareTypeLl06;
    @Bind(R.id.sure)
    Button sure;
    @Bind(R.id.cancel)
    Button cancel;
    private Context context;
    private Dialog dialog;
    private Display display;

    ArrayList<CompareBean> compareBeans = new ArrayList<>();

    /**
     * 一。内部接口，要求实现一个callback方法
     *
     * @author Administrator cuiweiyou.com
     */
    private ICallBack icb;

    View view;

    public CompareDialog(Context context) {
        this.context = context;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
    }

    public CompareDialog builder() {
        // 获取Dialog布局
        view = LayoutInflater.from(context).inflate(
                R.layout.dialog_compare, null);
        ButterKnife.bind(this, view);


        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (icb != null) {
                    // 这个方法在传入的回调器中实现
                    Bundle bundle = new Bundle();
                    icb.callback(bundle);
                }
            }
        });

        // 设置Dialog最小宽度为屏幕宽度
        view.setMinimumWidth(display.getWidth());

        // 定义Dialog布局和参数
        dialog = new Dialog(context, R.style.loadingDialogStyle);
        dialog.setContentView(view);
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.x = 0;
        lp.y = 0;
//        lp.height = (int) (display.getHeight() * 0.6); // 高度设置为屏幕的0.6
//        lp.width = (int) (display.getWidth() * 0.8); // 宽度设置为屏幕的0.65
        dialogWindow.setAttributes(lp);
        return this;
    }



    public void show() {
        dialog.show();
    }


    public void dismiss() {
        dialog.dismiss();
    }


    /**
     * 三。设置回调变量
     *
     * @param cb
     */
    // 如果不是使用上面接收icallback参数的(二)构造方法创建此自定义对话框，则需要使用此方法指定icb变量
    public void setCallBack(ICallBack cb) {
        icb = cb;
    }

    public interface ICallBack {
        void callback(Bundle bundle);
    }

    //1-身份确认，2-意识，3-血制品，4-吸氧方式，5-压疮，6-管道
    public CompareDialog setNum(ArrayList<CompareBean> compareBeans,String previousName,String nowName) {
        this.compareBeans = compareBeans;
        compareNameTv01 .setText(previousName);
        compareNameTv02 .setText(nowName);
        for (int i =0;i<compareBeans.size();i++){
           switch (compareBeans.get(i).getType())
           {
               case 1:
                   compareTypeLl01.setVisibility(View.VISIBLE);
                   compareType0101.setText("身份确认:"+compareBeans.get(i).getPreviou());
                   compareType0102.setText("身份确认:"+compareBeans.get(i).getNow());
                   break;
               case 2:
                   compareTypeLl02.setVisibility(View.VISIBLE);
                   compareType0201.setText("意识:"+compareBeans.get(i).getPreviou());
                   compareType0202.setText("意识:"+compareBeans.get(i).getNow());
                   break;
               case 3:
                   compareTypeLl03.setVisibility(View.VISIBLE);
                   compareType0301.setText("血制品:"+compareBeans.get(i).getPreviou());
                   compareType0302.setText("血制品:"+compareBeans.get(i).getNow());
                   break;
               case 4:
                   compareTypeLl04.setVisibility(View.VISIBLE);
                   compareType0401.setText(compareBeans.get(i).getPreviou());
                   compareType0402.setText(compareBeans.get(i).getNow());
                   break;
               case 5:
                   compareTypeLl05.setVisibility(View.VISIBLE);
                   compareType0501.setText(compareBeans.get(i).getPreviou());
                   compareType0502.setText(compareBeans.get(i).getNow());
                   break;
               case 6:
                   compareTypeLl06.setVisibility(View.VISIBLE);
                   compareType0601.setText(compareBeans.get(i).getPreviou());
                   compareType0602.setText(compareBeans.get(i).getNow());
                   break;
           }
        }
        return this;
    }


}
